# -*- coding: utf8 -*-
import urllib2
import urllib
import re
import os
import time
def download(url,category):
    content=urllib2.urlopen(url).read()
    name_pat=re.compile('<meta name="author" content="(.*?)">')
    time_pat=re.compile('id="PAGETIME" value="(.*?)">')
    filename='N'+re.findall(name_pat,content)[0]+'T'+re.findall(time_pat,content)[0]+'.xml'
    filename=filename.replace(":","-")
    filename=filename.replace('/','~')
    filename="F:\Python27\Zgr03"+os.sep+category+os.sep+filename.decode('utf-8')
    #os.chdir("F:\Python27\Zgr02"+os.sep+category)
    outfile = open(filename,'w')
    outfile.write(content)
    outfile.close()
    temple=[]
    temple.append(re.findall(name_pat,content)[0])
    temple.append(re.findall(time_pat,content)[0])
    temple.append(filename)
    #print(temple)
    #print(temple[0])
    time.sleep(0.01)
    return (1)
url=('http://www.baike.com/wiki/%E8%B4%A8%E5%AD%90-K%2FD%E7%BB%84%E7%BA%A7%E8%BF%90%E8%BD%BD%E7%81%AB%E7%AE%AD')
category='\xe9\x99\xa2\xe5\xa3\xab'+'T'
category=category.decode('utf-8')

download(url,category)
